Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
strip-indent
Advanced tools
The strip-indent npm package is used to remove the leading whitespace from every line in a given text block. This is particularly useful when working with multi-line strings that need to be displayed without indentation or when processing template literals in JavaScript that should not retain the formatting of the source code.
Strip indentation from a multi-line string
This feature allows you to remove the common leading whitespace from all lines in a text block, making it easier to handle formatted multi-line strings without unwanted indentation.
const stripIndent = require('strip-indent');
const text = ` line one
line two
line three`;
console.log(stripIndent(text));
Dedent is similar to strip-indent but also trims the trailing newline. It is often used in template literals to avoid first-line indentation and to ensure that the output does not end with a newline, making it slightly different in its approach compared to strip-indent.
While strip-indent removes indentation, indent-string adds indentation to each line in a string. This package can be considered the opposite of strip-indent. It allows specifying the number of spaces or the type of indentation (spaces or tabs), offering more flexibility depending on the user's needs.
Strip leading whitespace from every line in a string
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
Useful for removing redundant indentation.
$ npm install --save strip-indent
$ bower install --save strip-indent
$ component install sindresorhus/strip-indent
var str = '\tunicorn\n\t\tcake';
/*
unicorn
cake
*/
stripIndent('\tunicorn\n\t\tcake');
/*
unicorn
cake
*/
$ npm install --global strip-indent
$ strip-indent --help
Usage
$ strip-indent <file>
$ echo <string> | strip-indent
Example
$ echo '\tunicorn\n\t\tcake' | strip-indent
unicorn
cake
FAQs
Strip leading whitespace from each line in a string
The npm package strip-indent receives a total of 20,897,782 weekly downloads. As such, strip-indent popularity was classified as popular.
We found that strip-indent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.